<?php
 
defined('DSVH') or die('Restricted access');
 
//add chuc danh
function insertdomain($local){
    mysql_query("insert domain set 
    tieu_de = '".$local['tieu_de']."',
    avatar = '".$local['avatar']."',
    status = '".$local['status']."',
    cat_id = '".$local['cat_id']."',
    mo_ta_chung = '".$local['mo_ta_chung']."',
    mo_ta_chi_tiet = '".$local['mo_ta_chi_tiet']."',
    user_id = '".$_SESSION['can_bo_id']."',
    add_date = NOW(),
    tag = '".$local['tag']."',
    last_edit = NOW(),
    last_user_edit = '".$_SESSION['can_bo_id']."'",
    dbconnect());
}

function insertloaidomain($local){
    mysql_query("insert loai_domain set
    ten = '".$local['ten']."',
    user_id = '".$_SESSION['user_id']."',
    sap_xep = '".$local['sap_xep']."',
    rang_buoc = '".$local['rang_buoc']."',
    add_date = NOW()",
    dbconnect());
}

function editloaidomain($id, $local)
{
    mysql_query("update loai_domain set 
    ten = '".$local['ten']."',
    user_id = '".$_SESSION['can_bo_id']."',
    sap_xep = '".$local['sap_xep']."',
    rang_buoc = '".$local['rang_buoc']."'
    where id = '".(int)$id."'", dbconnect());
}

function rangbuocdm($id, $status)
{
    mysql_query("update loai_domain set 
    rang_buoc = '".$status."'
    where id = '".(int)$id."'", dbconnect());
}
//list chuc danh
function getListdomain($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM domain
        left join loai_domain  ON domain.cat_id = loai_domain.id
        order by domain_id desc LIMIT ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
    
function getListdomaintheothamso($catid, $status, $start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM domain
        left join loai_domain  ON domain.cat_id = loai_domain.id
        where loai_domain.id = '".$catid."'
        and status = '".$status."'
        order by domain_id desc LIMIT ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
    
    

function getListloaidomain($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM loai_domain
        order by id desc LIMIT ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
    
//ham lay du lieu phong ban theo id
function getdomain($id)
    {
    $pro = mysql_query("select * from domain where domain_id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
function getloaidomain($id)
    {
    $pro = mysql_query("select * from loai_domain where id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
//cap nhat trong muc sua
function editdomain($id, $local)
{
    mysql_query("update domain set
    tieu_de = '".$local['tieu_de']."',
    avatar = '".$local['avatar']."',
    status = '".$local['status']."',
    cat_id = '".$local['cat_id']."',
    mo_ta_chung = '".$local['mo_ta_chung']."',
    mo_ta_chi_tiet = '".$local['mo_ta_chi_tiet']."',
    add_date = NOW(),
    tag = '".$local['tag']."',
    last_edit = NOW(),
    last_user_edit = '".$_SESSION['can_bo_id']."'
    where domain_id = '".(int)$id."'", dbconnect());
}

// xoa thu muc
function deldomain($id){
    mysql_query("delete from domain where domain_id ='".(int)$id."'", dbconnect());
}

function totaldomain(){
   $result = mysql_query("select * from domain",dbconnect());
    return mysql_num_rows($result);
}

function totalloaidomain(){
   $result = mysql_query("select * from loai_domain",dbconnect());
    return mysql_num_rows($result);
}




?>